package com.dreamcar.auction.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Component entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "component", catalog = "assignment")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="discriminator", discriminatorType=DiscriminatorType.STRING, length=1)
public abstract class Component implements java.io.Serializable {

	// Fields

	private Integer idComponent;
	private String description;
	private String discriminator;
	private Set<Request> requests = new HashSet<Request>(0);
	private Set<CarModel> carModels = new HashSet<CarModel>(0);

	// Property accessors
	@Id
	@Column(name = "id_component", unique = true, nullable = false)
	public Integer getIdComponent() {
		return this.idComponent;
	}

	public void setIdComponent(Integer idComponent) {
		this.idComponent = idComponent;
	}

	@Column(name = "description", length = 45)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "discriminator", length = 1)
	public String getDiscriminator() {
		return this.discriminator;
	}

	public void setDiscriminator(String discriminator) {
		this.discriminator = discriminator;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "component")
	public Set<Request> getRequests() {
		return this.requests;
	}

	public void setRequests(Set<Request> requests) {
		this.requests = requests;
	}


	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "component_car_relation", catalog = "assignment", joinColumns = { @JoinColumn(name = "id_component", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_car_model", nullable = false, updatable = false) })
	public Set<CarModel> getCarModels() {
		return this.carModels;
	}

	public void setCarModels(Set<CarModel> carModels) {
		this.carModels = carModels;
	}

}